package com.tanjun.common.model;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

/**
 * 返回结果
 * @param <T>
 */

@AllArgsConstructor
@NoArgsConstructor
public class R<T> {
    @Getter
    private int code=200;
    @Getter
    private String msg="success";
    private Boolean success=true;
    @Getter
    private T data;

    public boolean isSuccess(){
        return this.success!=null&&this.success;
    }

    public static R OK() {
        return new R(200, "success", true, null);
    }
    public static <M> R OK(M data) {
        return new <M>R(200, "success", true, data);
    }

    public static R fail(String msg) {
        return new R(500, msg, false, null);
    }

    public static <M> R err(String msg) {
        return new R(500, msg, false, null);
    }

    public static <M> R err(Integer code,String msg) {
        return new R(code, msg, false, null);
    }

    /**
     * 无权限
     * @return
     */
    public static R NO_PERMISSION() {
        return new R(403, "无权限", false, null);
    }

    public static R NO_LOGIN() {
        return new R(401, "未认证", false, null);
    }

    public static R NO_USER() {
        return new R(407, "用户未注册", false, null);
    }

    public static R USER_DISABLE() {
        return new R(408, "用户被禁用", false, null);
    }

    public static R TOKEN_EXPIRED() {
        return new R(409, "token已过期", false, null);
    }

}
